import java.awt.*;

public class EnemyShip extends Sprite{

	private static final int STEP = -10;   // moving left
	private static final int STEP_OFFSET = 2;
	
	private double sinFactor = 0.1;
	private int initialX = 150;
	

	private JackPanel jp;    // tell JackPanel about colliding with jack
	private ShipSprite ship;

	public EnemyShip(int w, int h, ImagesLoader imsLd,
			JackPanel jp, ShipSprite s) 
	{ super( w, h, 500, 360, imsLd, "enemy1Left");  
//	the ball is positioned in the middle at the panel's rhs
	this.jp = jp;
	ship = s;
	initPosition(w,h);
	} // end of FireBallSprite

	private void initPosition(int w, int h)
	// adjust the fireball's position and its movement left
	{
		setPosition(w, h);   
		setStep(0, 0);   // move left
	} // end of initPosition()

	private int enemyTragetoryY(){

		return 150+(int)Math.round(110*(Math.sin(locx*0.1)));
		//return locy+=locy+1;

	}

	private int getRandRange(int x) 
	// random number generator between -x and x
	{   return ((int)(100 * x * Math.random())) - x;  }

	public void updateSprite() 
	{ 
		hasHitMissle();
		goneOffScreen();
		locx -= +1;
		
		locy = enemyTragetoryY();
		//System.out.println(locy);
		//setPosition(locx,enemyTragetoryY());
		//System.out.print(this.locx+" "+this.locy);
		super.updateSprite();
	}

	private void hasHitMissle()
	/* If the ball has hit jack, tell JackPanel (which will
	     display an explosion and play a clip), and begin again.
	 */
	{ 
		if (ship.missle != null){


			Rectangle missleBox = ship.missle.getMyRectangle();
			//missleBox.grow(-missleBox.width/3, 0);   // make jack's bounded box thinner

			if (missleBox.intersects( getMyRectangle() )) {    // jack collision?
				jp.showExplosion(ship.missle.locx, ship.missle.locy);  
				// tell JackPanel, supplying it with a hit coordinate
				ship.missle = null;
				//initPosition();
			}
		}
	} // end of hasHitJack()
	private void goneOffScreen()
	// when the ball has gone off the lhs, start it again.
	{
		//if (((locx+getWidth()) <= 0) && (dx < 0)) // off left and moving left
		//initPosition();   // start the ball in a new position
	}  // end of goneOffScreen()


}
